#include "Object.h"
Object fa;
Object::Object()
{
    //ctor
    int r;
    r=pthread_rwlock_init( &m_rwlock, NULL);
    if(r!=0)
    {
        r=1;
    }
    m_address=0;
    m_size=0;
    m_new=-1;
}
Object::~Object()
{
    //dtor
    pthread_rwlock_destroy(&m_rwlock);

}
void Object::initData(void *data,int size)
{
    m_size=size;
    if(m_address)
        delete [] m_address;
    m_address=new char[size];
    m_new=0;
    if(data==NULL)
        return;
    for(int i=0;i<m_size;i++)
        ( (char *)m_address)[i]=((char *)data)[i];
}
int Object::readData(void *data)
{
    while(!isInit())
        ;
    pthread_rwlock_rdlock(&m_rwlock);
    for(int i=0;i<m_size;i++)
        ((char *)data)[i]=( (char *)m_address)[i];

    pthread_rwlock_unlock(&m_rwlock);
    return m_new;
}
int Object::writeData(void *data)
{
    pthread_rwlock_wrlock(&m_rwlock);
    for(int i=0;i<m_size;i++)
        ( (char *)m_address)[i]=((char *)data)[i];
    m_new=!m_new;

    pthread_rwlock_unlock(&m_rwlock);
    return m_new;
}

